package com.diamond.smart.data.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.diamond.smart.data.vo.DuringDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.diamond.smart.data.entity.VoltageDataEntity;
import com.diamond.smart.data.service.VoltageDataService;
import com.diamond.common.utils.PageUtils;
import com.diamond.common.utils.R;


/**
 * @author SunKewei
 * @email skw777jo@163.com
 * @date 2022-04-26 16:06:18
 */
@RestController
@RequestMapping("data/voltagedata")
public class VoltageDataController {

    @Autowired
    private VoltageDataService voltageDataService;

    /**
     * 查询规定时间段的某个设备的数据
     *
     * @param vo
     * @return
     */
    @PostMapping("/duringData")
    public R getDuringDataByDeviceId(@RequestBody DuringDataVo vo) {
        List<VoltageDataEntity> data = voltageDataService.getDuringDataByDeviceId(vo);
        return R.ok().put("data", data);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = voltageDataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{dataId}")
    public R info(@PathVariable("dataId") Long dataId) {
        VoltageDataEntity voltageData = voltageDataService.getById(dataId);

        return R.ok().put("voltageData", voltageData);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody VoltageDataEntity voltageData) {
        voltageDataService.save(voltageData);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody VoltageDataEntity voltageData) {
        voltageDataService.updateById(voltageData);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] dataIds) {
        voltageDataService.removeByIds(Arrays.asList(dataIds));

        return R.ok();
    }

}
